package com.ruoyi.web.contrller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.Caigou;
import com.ruoyi.web.service.ICaigouService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 采购Controller
 */
@RestController
@RequestMapping("/warehouse/caigou")
public class CaigouController extends BaseController {
    @Autowired
    private ICaigouService caigouService;

    /**
     * 查询采购列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:caigou:list')")
    @GetMapping("/list")
    public TableDataInfo list(Caigou caigou)
    {
        startPage();
        List<Caigou> list = caigouService.selectCaigouList(caigou);
        return getDataTable(list);
    }

    /**
     * 获取采购详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:caigou:query')")
    @GetMapping(value = "/{caigouid}")
    public AjaxResult getInfo(@PathVariable("caigouid") Long caigouid)
    {
        return success(caigouService.selectCaigouByCaigouid(caigouid));
    }

    /**
     * 新增采购
     */
    @PreAuthorize("@ss.hasPermi('warehouse:caigou:add')")
    @Log(title = "采购", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Caigou caigou)
    {
        return toAjax(caigouService.insertCaigou(caigou));
    }

    /**
     * 修改采购
     */
    @PreAuthorize("@ss.hasPermi('warehouse:caigou:edit')")
    @Log(title = "采购", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Caigou caigou)
    {
        return toAjax(caigouService.updateCaigou(caigou));
    }

    /**
     * 删除采购
     */
    @PreAuthorize("@ss.hasPermi('warehouse:caigou:remove')")
    @Log(title = "采购", businessType = BusinessType.DELETE)
    @DeleteMapping("/{caigouids}")
    public AjaxResult remove(@PathVariable Long[] caigouids)
    {
        return toAjax(caigouService.deleteCaigouByCaigouids(caigouids));
    }
}
